object Primes {
    def main() : Unit = {
    	println("Found "+(new PrimeC().CalcPrimes(1000))+" primes!");
    }
}
class PrimeC {
    def CalcPrimes(Ceil : Int) : Int = {
    	/* Methodology : check each number for divisibility by one of the primes found up until now. */
    	var p : Int[]; // Array of currently found primes
    	var c : Int;   // Current prime count
    	var i : Int;   // Current number we're testing
    	var j : Int;   // Iterator
    	var isPrime : Bool; // Says it all
    	p = new Int[Ceil];
    	p[0] = 2;
    	c = 1;
    	i = p[0] + 1;
    	while (i < Ceil) {
    		j = 0;
    		isPrime = true;
    		while (j<c && isPrime) {
    			// tool doesn't do modulo, so I used an ugly workaround
    			if (((i / p[j]) * p[j]) == i) isPrime = false;
    			j = j + 1;
    		}
    		if (isPrime) {
    			println(i);
	    		p[c] = i;
	    		c = c + 1;
    		}
    		i = i + 1;
    	}
    	return c;
    }
}
